package com.lagou.controller;

import com.lagou.entity.Order;
import com.lagou.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 下单入口
     *
     * @return
     */
    @RequestMapping("/order")
    public String order() {
        Order order = new Order();
        order.setUserId(UUID.randomUUID().toString());
        boolean result = orderService.order(order);

        return result ? "success" : "error";
    }

    /**
     * 支付入口
     *
     * @param orderId
     * @return
     */
    @RequestMapping("/pay")
    public String pay(@RequestParam String orderId) {
        return orderService.pay(orderId);
    }
}
